<!-- 顶部导航查询条 -->
<template>
    <div class="navigationBar">
        <!-- <div class="title" v-if="cTitle != '无'">
            {{ changeTitle ? changeTitle : cTitle ? cTitle : title }}
        </div> -->
        <div class="search">
            <slot></slot>
        </div>
    </div>
</template>

<script>
import {OtherCommon} from '@/libs/otherCommon'
import {SessionCommon} from '@/libs/sessionCommon'
export default {
    name: 'navigationBar',
    props: ['customTitle'],
    data() {
        return {
            title: '',
            changeTitle: ''
        }
    },
    watch: {
        //当路由变更时，执行打开页面的方法
        $route: {
            async handler(v) {
                this.changeTitle = await this.getName(v.name)
            },
            immediate: true
        }
    },
    computed: {
        cTitle() {
            return this.customTitle
        }
    },
    destroyed() {
        this.changeTitle = ''
    },
    methods: {
        async getName(menuUrl) {
            const data = await OtherCommon.getAllMenu()
            try {
                return data.find((t) => t.menuUrl == menuUrl).title
            } catch (error) {
                // console.log(error.message)
                if (menuUrl == 'mcIndex') {
                    const childMenu = data.filter((t) => t.menuUrl)
                    return childMenu[0].menuUrl == 'largeScreen' ? childMenu[1].title : childMenu[0].title
                }
                return ''
            }
        }
    },
    mounted() {
        let cMenuInfo = SessionCommon.getCurrentMenuInfo()
        if (cMenuInfo) {
            cMenuInfo = JSON.parse(cMenuInfo)
            if (cMenuInfo.menuUrl == 'largeScreen') {
                const secordMenu = this.menuListData?.filter((t) => t.menuUrl != '')?.[1]
                this.title = secordMenu?.title ?? ''
            } else {
                this.title = cMenuInfo.title
            }
        }
    }
}
</script>

<style scoped lang="scss">
.navigationBar {
    /* height: 36px; */
    line-height: 36px;
    background-color: #fff;
    display: flex;
    .searchContent {
        display: flex;
        justify-content: flex-end;
        margin-right: 0;
    }
}

.navigationBar .title {
    position: relative;
    text-indent: 20px;
    font-size: 15px;
}

.navigationBar .title::before {
    background-color: rgb(22, 132, 252);
    height: 16px;
    width: 3px;
    content: '';
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 1;
}

.navigationBar .search {
    flex: 1;
    margin-left: 20px;
    margin-right: 10px;
    text-align: right;
}
</style>
